Show language: C# VB.NET Both
This Windows Forms example is intended to demonstrate a basic programmatic implementation. From the button click event, the website source is imported and the index fully built ready for searching.
Reference these DLL's in your project, KeyotiX.SearchEngine.Core, KeyotiX.SearchEngine.License, KeyotiX.Text.LemmaGenerator.dll, KeyotiX.Text.MSOffice.dll - where X is 2 for .NET 2 and 4 for .NET 4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Keyoti.SearchEngine;
using Keyoti.SearchEngine.Index;
using Keyoti.SearchEngine.DataAccess.IndexableSourceRecords;
using Keyoti.SearchEngine.Search;
namespace WindowsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Configuration configuration = new Configuration();
configuration.IndexDirectory = "C:/YourSite/IndexDirectory";
//---Import pages from website.
DocumentIndex documentIndex = new DocumentIndex(configuration);
try{
documentIndex.ImportWebsite("http://www.yoursite.com");
} finally {
documentIndex.Close();
}
//---Search Index
SearchAgent sa = new SearchAgent("EnterLicenseKeyHere", configuration);
SearchResult res = sa.Search("search terms", 1, 10); //res now holds a collection of ResultItem objects
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports Keyoti.SearchEngine
Imports Keyoti.SearchEngine.Index
Imports Keyoti.SearchEngine.DataAccess.IndexableSourceRecords
Imports Keyoti.SearchEngine.Search
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim configuration As Keyoti.SearchEngine.Configuration = New Configuration
configuration.IndexDirectory = "C:/YourSite/IndexDirectory"
'---Import pages from website.
Dim documentIndex As DocumentIndex = New DocumentIndex(configuration)
Try
documentIndex.ImportWebsite("http://www.yoursite.com")
Finally
documentIndex.Close()
End Try
'---Search Index
Dim sa As SearchAgent = New SearchAgent("EnterLicenseKeyHere", configuration)
Dim res As SearchResult = sa.Search("search terms", 1, 10) 'res now holds a collection of ResultItem objects
End Sub
End Class
The try-finally constructs ensure that the index is closed even if an exception occurs.